package com.weibo.net;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

public class Weibo
{
  public static String APP_KEY;
  public static String APP_SECRET;
  public static String SERVER = "http://api.t.sina.com.cn/";
  public static String URL_ACCESS_TOKEN;
  public static String URL_AUTHENTICATION;
  public static String URL_AUTHORIZE;
  public static String URL_OAUTH_TOKEN = "http://api.t.sina.com.cn/oauth/request_token";
  private static Weibo mWeiboInstance;
  private AccessToken mAccessToken = null;
  private RequestToken mRequestToken = null;

  static
  {
    URL_AUTHORIZE = "http://api.t.sina.com.cn/oauth/authorize";
    URL_ACCESS_TOKEN = "http://api.t.sina.com.cn/oauth/access_token";
    URL_AUTHENTICATION = "http://api.t.sina.com.cn/oauth/authenticate";
    APP_KEY = "2832649083";
    APP_SECRET = "191a6c08a5d3f783a5bd0de5accd180b";
    mWeiboInstance = null;
  }

  private Weibo()
  {
    Utility.setRequestHeader("Accept-Encoding", "gzip");
    Utility.setTokenObject(this.mRequestToken);
  }

  public static Weibo getInstance()
  {
    if (mWeiboInstance == null)
      mWeiboInstance = new Weibo();
    return mWeiboInstance;
  }

  public void addOauthverifier(String paramString)
  {
    this.mRequestToken.setVerifier(paramString);
  }

  public void authorizeCallBack(int paramInt1, int paramInt2, Intent paramIntent)
  {
  }

  public AccessToken generateAccessToken(Context paramContext, RequestToken paramRequestToken)
    throws WeiboException
  {
    Utility.setAuthorization(new AccessTokenHeader());
    WeiboParameters localWeiboParameters = new WeiboParameters();
    localWeiboParameters.add("oauth_verifier", this.mRequestToken.getVerifier());
    localWeiboParameters.add("source", APP_KEY);
    AccessToken localAccessToken = new AccessToken(Utility.openUrl(paramContext, URL_ACCESS_TOKEN, "POST", localWeiboParameters, this.mRequestToken));
    this.mAccessToken = localAccessToken;
    return localAccessToken;
  }

  public AccessToken getAccessToken()
  {
    return this.mAccessToken;
  }

  public RequestToken getRequestToken(Context paramContext, String paramString1, String paramString2, String paramString3)
    throws WeiboException
  {
    Utility.setAuthorization(new RequestTokenHeader());
    WeiboParameters localWeiboParameters = new WeiboParameters();
    localWeiboParameters.add("oauth_callback", paramString3);
    RequestToken localRequestToken = new RequestToken(Utility.openUrl(paramContext, URL_OAUTH_TOKEN, "POST", localWeiboParameters, null));
    this.mRequestToken = localRequestToken;
    return localRequestToken;
  }

  public AccessToken getXauthAccessToken(Context paramContext, String paramString1, String paramString2, String paramString3, String paramString4)
    throws WeiboException
  {
    Utility.setAuthorization(new XAuthHeader());
    WeiboParameters localWeiboParameters = new WeiboParameters();
    localWeiboParameters.add("x_auth_username", paramString3);
    localWeiboParameters.add("x_auth_password", paramString4);
    localWeiboParameters.add("oauth_consumer_key", APP_KEY);
    AccessToken localAccessToken = new AccessToken(Utility.openUrl(paramContext, URL_ACCESS_TOKEN, "POST", localWeiboParameters, null));
    this.mAccessToken = localAccessToken;
    return localAccessToken;
  }

  public String request(Context paramContext, String paramString1, WeiboParameters paramWeiboParameters, String paramString2, AccessToken paramAccessToken)
    throws WeiboException
  {
    Utility.setAuthorization(new RequestHeader());
    return Utility.openUrl(paramContext, paramString1, paramString2, paramWeiboParameters, this.mAccessToken);
  }

  public void setAccessToken(AccessToken paramAccessToken)
  {
    this.mAccessToken = paramAccessToken;
  }

  public void setRequestToken(RequestToken paramRequestToken)
  {
    this.mRequestToken = paramRequestToken;
  }

  public void setupConsumerConfig(String paramString1, String paramString2)
  {
    APP_KEY = paramString1;
    APP_SECRET = paramString2;
  }

  public boolean share2weibo(Activity paramActivity, String paramString1, String paramString2, String paramString3, String paramString4)
    throws WeiboException
  {
    if (TextUtils.isEmpty(paramString1))
      throw new WeiboException("token can not be null!");
    if (TextUtils.isEmpty(paramString2))
      throw new WeiboException("secret can not be null!");
    if ((TextUtils.isEmpty(paramString3)) && (TextUtils.isEmpty(paramString4)))
      throw new WeiboException("weibo content can not be null!");
    Intent localIntent = new Intent(paramActivity, ShareActivity.class);
    localIntent.putExtra("com.weibo.android.accesstoken", paramString1);
    localIntent.putExtra("com.weibo.android.token.secret", paramString2);
    localIntent.putExtra("com.weibo.android.content", paramString3);
    localIntent.putExtra("com.weibo.android.pic.uri", paramString4);
    paramActivity.startActivity(localIntent);
    return true;
  }
}